package com.tanhua.dubbo.mapper;

import com.tanhua.vo.OptionVo;
import org.apache.ibatis.annotations.*;

import java.util.*;

/**
 * @author 钱柏羽
 * @date 2021/07/18
 */
public interface OptionVoMapper {

    @Select("SELECT _option,score FROM tb_option tb1,tb_survey_score tb2 \n" +
            "WHERE tb1.`qid`=tb2.`qid` AND tb1.id=tb2.`oid` AND tb1.`qid`=#{qid}")
     List<OptionVo>findOptionVoByQid(@Param("qid") Integer qid);


    @Delete("DELETE FROM tb_option WHERE qid=#{qid}")
    void deleteOptionsByQid(@Param("qid") Integer questionId);
    @Delete("DELETE FROM tb_survey_score WHERE qid=#{qid}")
    void deleteOptionsScoreByQid(@Param("qid") Integer questionId);



    @Update("UPDATE tb_survey_score SET score=#{score} WHERE qid=#{qid} AND oid='${c}'")
    void updateScoreByQid(@Param("qid") Integer qid, @Param("c") char c,@Param("score") Integer score);

    @Update("UPDATE tb_option SET _option=#{newOption} WHERE qid=#{qid} AND id='${c}'")
    void updateOptionByQid(Integer qid, char c,@Param("newOption") String newOption);

    @Insert("INSERT INTO tb_survey_score VALUES(#{qid},'${c}',#{score})")
    void saveOptionScoreByQid(@Param("qid") Integer qid, @Param("c") char c, @Param("score") Integer score);

    @Insert("INSERT INTO tb_option VALUES('${c}',#{newOption},#{qid},NULL)")
    void saveOptionByQid(@Param("qid") Integer qid,@Param("c") char c, @Param("newOption") String newOption);
}
